package com.example.demo.mapper;

import com.example.demo.entity.StudentInfo;
import com.example.demo.vo.StudentClassInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface StudentInfoMapper {
    //SQL 语句操作后的返回类型，一个有意义的方法名：参数列表
    @Select("SELECT * FROM idea.student_info where stu_name like '%${name}%'")
    List<StudentInfo> getAllStudentInfo(String name);

    @Select("select stu.*,cls.className from student_info stu join classinfo cls on stu.clsid = cls.clsid where stu_name like '%${stuName}%'")
    List<StudentClassInfo> getAllStuAndClassByName(String stuName);

    @Delete("delete from student_info where stuid = #{stuid}")
    Integer deleteByID(Integer stuid);

    @Select("select stu.*,cls.className from student_info stu join classinfo cls on stu.clsid = cls.clsid\n" +
            "where stu_name like '%${stuName}%' and stu.clsid = #{clsid}")
    List<StudentClassInfo> getAllClassByclsAndName(@Param("stuName")String stuName, @Param("clsid") Integer clsid);

    @Insert("insert into student_info(stu_no,stu_name,stu_sex,stu_birthday,stu_education,stu_interest,my_color,create_date,clsid)\n" +
            "value (#{stu_no},#{stu_name},#{stu_sex},#{stu_birthday},#{stu_education},#{stu_interest},#{my_color},sysdate(),#{clsid});")
    Integer insertStudentInfo(StudentInfo studentInfo);

    @Update("update student_info set clsid=#{clsid},stu_no=#{stu_no},stu_name=#{stu_name},stu_sex=#{stu_sex},stu_birthday=#{stu_birthday},stu_education=#{stu_education},stu_interest=#{stu_interest},my_color=#{my_color}\n" +
            "where stuid =#{stuid}")
    Integer updateStudentInfo(StudentInfo studentInfo);

//scnabc a
}
